{block name=body}
<div id="maincont">
    <div class="container">
        <div class="row">
            <div class="col-sm-12" id="cartdet">
                {if $productsOnCart }
                <div class="hidden-xs" id="steps">
                    <span class="bold">订单汇总</span> | 个人信息 {if $classQtyOnCart gt 0}| 学生信息 {/if}| 付款
                </div>
                <div class="visible-xs">
                    <span class="bold">步骤 {if $classQtyOnCart gt 0}1 / 4{else}1 / 3{/if}</span>
                </div>
                <div class="row headings">
                    <div class="visible-xs col-xs-3"></div>
                    <div class="hidden-xs col-sm-6 col-md-7">商品</div>
                    <div class="col-xs-3 col-sm-2 col-md-2 text-right">数量</div>
                    <div class="col-xs-3 col-sm-2 col-md-1 text-right">单价</div>
                    <div class="col-xs-3 col-sm-2 col-md-2 text-right">小计</div>
                </div>
                <form class="form-horizontal" id="shopping-cart-form" accept-charset="UTF-8" action="" method="post">
                    <div class="row tallbox">
{assign var=hasStandardClass value=0}
{assign var=hasTshirt value=0}
    {foreach from=$productsOnCart item=item}
        {if $item.cartitem_enrolment_type eq 'S'}
            {assign var=hasStandardClass value=1}
        {/if}
        {if $item.cartitem_product_name|strstr:"shirt"}
            {assign var=hasTshirt value=1}
        {/if}
                        <div id="{$item.cartitem_id}" class="prod-item cartitem">
                            <div class="col-xs-12 col-sm-6 col-md-7 bluetext">
                                <a href="{$item.url}">{$item.cartitem_product_name}
                                          {if $item.attributes } 
                                                {assign var='hasweek' value=0}
                                                
                                                {if $item.cartitem_class_flag eq 1 && $item.cartitem_enrolment_type eq 'T' } 
                                                    【{getdatebyweekdaystartdate weekday=$item.class_weekday startdate=$item.term_start_date weeksafter=$item.attributes.0.cartitem_attr_attr_value_name-1 dateformat='Y/m/d'}】
                                                {else}
                                                    {foreach from=$item.attributes item=attr name=attributesarr}
                                                        {if $attr.cartitem_attr_attribute_name eq 'week'}
                                                                {assign var='hasweek' value=$hasweek+1}
                                                        {else}
                                                             / {$attr.cartitem_attr_attribute_name}: {$attr.cartitem_attr_attr_value_name}
                                                        {/if} 
                                                    {/foreach}
                                                    {if $hasweek gt 0}
                                                        【课程共 {$hasweek} 周】
                                                    {/if}
                                                {/if}
                                            
                                        {/if}
                                    </a>
                            </div>
                            <div class="visible-xs col-xs-3"></div>
                            <div class="col-xs-3 col-sm-2 col-md-2 quant text-right">
                                <a class="shopping-cart-icons" href="javascript:void(0)" onclick="deleteItem('{$item.cartitem_id}');">
                                    <span class="glyphicon glyphicon-trash"></span>
                                </a>
                                <select id="quantity" class="quantity" name="qty[{$item.cartitem_id}]">
                                    {if $item.cartitem_class_flag eq 1}{assign var='max' value=$item.availability.available}{else}{assign var='max' value=150}{/if} {if $max lt $item.cartitem_quantity} {assign var='max' value=$item.cartitem_quantity} {/if} {for $opt=1 to $max}
                                    <option value="{$opt}" {if $item.cartitem_quantity eq $opt}selected{/if}>{$opt}</option>
                                    {/for}
                                </select>
                                <div id="qty-discount-{$item.cartitem_id}">{if $item.productqty_modifier.productqty_modifier neq 0}(-{$item.productqty_modifier.productqty_modifier|number_format:0:".":','}%){/if}</div>
                            </div>
                            <div class="col-xs-3 col-sm-2 col-md-1 text-right" id="priceunit-{$item.cartitem_id}">{$CURRENCY_SYMBOL}{$item.cartitem_product_price|number_format:2:".":","}</div>
                            <div class="col-xs-3 col-sm-2 col-md-2 text-right" id="subtotal-{$item.cartitem_id}">{$CURRENCY_SYMBOL}{$item.cartitem_subtotal|number_format:2:".":","}</div>
                        </div>
                        {/foreach}
                    </div>
                </form>
                <br />
                <div class="row">
                    <div class="col-sm-12">
                        <div class="row tallrow hide">
                            <div class="col-sm-offset-2 col-md-offset-2 col-sm-5 col-md-5 ">
                            </div>
                            <div class="col-xs-5 col-sm-2 col-md-3 shopping-label">商品总金额</div>
                            <!-- The following SUBTOTAL value was intentionally changed to TOTAL  -->
                            <div class="col-xs-7 col-sm-3 col-md-2 num text-right" id="subtotal" data-value="{$totals.total}">{$CURRENCY_SYMBOL}{$totals.subtotal|number_format:2:".":","}</div>
                        </div>
                        {if $totals.discount gt 0}
                        <div class="row tallrow" id="disccode">
                            <form class="form-horizontal" id="discount-form" accept-charset="UTF-8" action="/process/cart" method="post">
                                <input type="hidden" value="applyDiscount" name="action" id="action" />
                                <div class="col-xs-12 col-sm-4 col-md-2 text-left">
                                    <!-- Discount code -->
                                </div>
                                <div class="col-xs-7 col-sm-4 col-md-2">
                                    <!-- <input class="form-control" type="text" placeholder="ENTER CODE" id="promo" value="{if $post}{$post.discount_code}{else}{$cart.cart_discount_code}{/if}" name="discount_code"/> -->
                                </div>
                                <div class="col-xs-5 col-sm-4 col-md-2">
                                    <!--  <button class="enquire" onclick="$('#discount-form').submit();"><span>Apply</span></button> -->
                                </div>
                                <div class="col-xs-6 col-sm-offset-4 col-md-offset-0 col-sm-5 col-md-4 shopping-label">
                                    {if $error}<span class="invalid">{$error}</span>{else}<small><b>{if $totals.discount gt 0}家庭折扣价<!-- {$cart.cart_discount_description} -->{/if}</b></small>{/if}
                                </div>
                                <div class="col-xs-6 col-sm-3 col-md-2 num text-right" id="discount">
                                    {if $totals.discount gt 0}
                                    <small><b>{$CURRENCY_SYMBOL}-{$totals.discount|number_format:2:".":","}</b></small> {else} {$CURRENCY_SYMBOL}0.00 {/if}
                                </div>
                            </form>
                        </div>
                        {/if}
                        <div class="row hide tallrow">
                            <div class="col-xs-5 col-sm-4 col-sm-offset-5 col-md-offset-7 col-md-3 shopping-label">
                                <form class="form-horizontal" id="checkout1-form" accept-charset="UTF-8" action="/process/cart" method="post">
                                    <input type="hidden" value="checkout1" name="action" id="action" />
                                    <input type="hidden" value="" name="shipMethod" id="shipMethod" />
                                    <input type="hidden" value="" id="shippingMethod" name="shipFee"> 运费
                                </form>
                            </div>
                            <!-- The following SUBTOTAL value was intentionally changed to TOTAL  -->
                            <div class="col-xs-7 col-sm-3 num text-right col-md-2" id="shipping-fee">{$CURRENCY_SYMBOL}-未知-</div>
                        </div>
                        <div class="row tots tallrow">
                            <div class="col-sm-7 col-md-7">
                            </div>
                            <div class="col-xs-5 col-sm-2 col-md-3 shopping-label bold">
                                总价
                            </div>
                            <div class="col-xs-7 col-sm-3 col-md-2 num text-right bold num" id="total"></div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-7">
                        {if $hasStandardClass neq 0 && $hasTshirt eq 0}
                        <div class="small buy-ts">
                            <div class="pull-left" style="margin-right:10px;"><img src="images/tshirt-sml.png" /></div>
                            <p><b>我们所有的课程均需要穿制服（T恤）。如果您还没有T恤，请先选择 <a href="/products/merchandise/t-shirt">短袖</a> 或 <a href="/products/merchandise/long-sleeve-shirt">长袖</a> T恤。</b></p>
                        </div>
                        {/if}
                    </div>
                    <div class="col-sm-3 col-sm-offset-2 text-right">
                        <button class="enquire" onclick="$('#checkout1-form').submit();"><span>去结算</span></button>
                    </div>
                </div>
                <br />
                {else}
                <div class="empty-cart">
                    <h2 class="title">您的购物车是空的。</h2>
                    <p>请不要两手空空的离开我们，试着去搜索一些<a href="/enrol" title="click to find classes">课程</a> 或者购买一些很酷的 <a href="/products" title="click to view merchandise">商品</a>!</p>
                    <br>
                </div>
                {/if}
            </div>
        </div>
    </div>
</div>
{include file='helpblock.tpl'} {/block} 

{block name=tail}
<script type="text/javascript">
$(function() {
    $('select').selectBoxIt();
});

$(document).ready(function() {
    $('#checkout1-form').validate({
        onkeyup: false,
        onclick: false
    });
    calculateTotal();


    var keyStop = {
        8: ":not(input:text, textarea, input:file, input:password)", // stop backspace = back
        13: "input:text, input:password", // stop enter = submit 

        end: null
    };
    $(document).bind("keydown", function(event) {
        var selector = keyStop[event.which];

        if (selector !== undefined && $(event.target).is(selector)) {
            event.preventDefault(); //stop event
        }
        return true;
    });
});
</script>
{/block}
